import java.util.ArrayList;
import java.util.Iterator;
import java.util.Vector;


public class StevesSupertagParser 
{
	ArrayList<String> dividers;
	
	public StevesSupertagParser(ArrayList<String> dividers)
	{
		this.dividers = dividers;
	}
	
	public ArrayList<String> parseSupertag(String input)
	{
		ArrayList<String> result = new ArrayList<String>();
		int numLP = 0;
		int numRP = 0;
		int start = 0;
		for(int a = 0; a < input.length(); a++)
		{
			if(input.charAt(a) == '(')
			{
				numLP++;
				while(numLP > numRP)
				{
					a++;
					if(input.charAt(a) == '(')
						numLP++;
					else if(input.charAt(a) == ')')
						numRP++;
				}
			}
			else if(dividers.contains(input.substring(a,a+1)))
			{
				String candidate = input.substring(start,a);
				if(!candidate.equals(""))
				{
					result.add(input.substring(start, a));
					start = a;
				}
			}
		}
		result.add(input.substring(start, input.length()));
		return result;
	}
	
	public int indexOfNextDivider(String data)
	{
		int min = 1000;
		Iterator<String> i = dividers.iterator();
		while(i.hasNext())
		{
			String div = i.next();
			int index = data.indexOf(div);
			if(index < min)
				min = index;
		}
		if(min == 1000)
			return -1;
		else return min;
	}
}
